Ext.ns("BookTypeView");  
var BookTypeView = function() {
	return this.setup();
};

BookTypeView.prototype.setup = function() {
	var e;
	var f = new Ext.tree.TreePanel({
		region : "west",
		id : "treePanel",
		title : "书籍目录显示",
		collapsible : true,
		autoScroll : true,
		split : true,
		height : 800,
		width : 180,
		tbar : new Ext.Toolbar({
			items : [ {
				xtype : "button",
				iconCls : "btn-refresh",
				text : "刷新",
				handler : function() {
					f.root.reload();
				}
			}, {
				xtype : "button",
				text : "展开",
				iconCls : "btn-expand",
				handler : function() {
					f.expandAll();
				}
			}, {
				xtype : "button",
				text : "收起",
				iconCls : "btn-collapse",
				handler : function() {
					f.collapseAll();
				}
			} ]
		}),
		
		loader : new Ext.tree.TreeLoader({
			url : __ctxPath + "/listBookType.do"
		}),
		
		root : new Ext.tree.AsyncTreeNode({
			expanded : true
		}),
		
		rootVisible : false
	});
	
	
	if (isGranted("_BookTypeAdd") || isGranted("_BookTypeEdit") || isGranted("_BookTypeDel")) {
		f.on("contextmenu", b, f);
	}
	
	var h = new Ext.menu.Menu({
		id : "BookTypeTreeMenu",
		items : []
	});
	
	if (isGranted("_BookTypeAdd")) {
		h.add({
			text : "新建书籍目录信息",
			iconCls : "btn-add",
			scope : this,
			handler : m
		});
	}
	
	if (isGranted("_BookTypeEdit")) {
		h.add({
			text : "修改书籍目录信息",
			iconCls : "btn-edit",
			scope : this,
			handler : i
		});
	}
	
	if (isGranted("_BookTypeDel")) {
		h.add({
			text : "删除书籍目录信息",
			iconCls : "btn-delete",
			scope : this,
			handler : j
		});
	}
	
	function b(n, o) {
		e = new Ext.tree.TreeNode({
			id : n.id,
			text : n.text
		});
		h.showAt(o.getXY());
	}
	
	function m() {
		var n = e.id;
		var o = Ext.getCmp("bookTypeForm");
		if (o == null) {
			if (n != 0) {
				new BookTypeForm({
					nodeId : n
				}).show();
			} else {
				new BookTypeForm({
					nodeId : 0
				}).show();
			}
		}
	}
	
	function j() {
		var n = e.id;
		var o = Ext.getCmp("treePanel");
		if (n != 0) {
			Ext.Msg.confirm("删除操作", "你确定删除书籍目录?", function(p) {
				if (p == "yes") {
					Ext.Ajax.request({
						url : __ctxPath + "/removeBookType.do?bookCatalogId=" + n,
						success : function(q, s) {
							var r = Ext.util.JSON.decode(q.responseText);
							if (r.success == false) {
								Ext.ux.Toast.msg("操作信息", r.message);
							} else {
								Ext.ux.Toast.msg("操作信息", "删除成功!");
							}
							o.root.reload();
						},
						failure : function(q, r) {
						}
					});
				}
			});
		} else {
			Ext.ux.Toast.msg("警告", "该信息不能被删除");
		}
	}
	function i() {
		var n = e.id;
		if (n != 0) {
			var o = Ext.getCmp("bookTypeForm");
			if (o == null) {
				new BookTypeForm().show();
				o = Ext.getCmp("bookTypeForm");
			}
			o.form.load({
				url : __ctxPath + "/detailBookType.do",
				params : {
					bookCalalogId : n
				},
				method : "post",
				deferredRender : true,
				layoutOnTabChange : true,
				success : function() {
				},
				failure : function() {
					Ext.ux.Toast.msg("编辑", "载入失败");
				}
			});
		} else {
			Ext.ux.Toast.msg("警告", "该信息不能修改！");
		}
	}
	
	var a = new Ext.Panel({
		id : "BookTypeView",
		title : "书籍目录信息",
		closable : true,
		iconCls : "menu-department",
		layout : "border",
		items : [ f ]
	});
	return a;
};
